import wepy from 'wepy'

export default class Home extends wepy.mixin {
    data = {
      // 轮播图数据
      swipers:[],
      //导航数据
      navCate:[],
      //商品楼层数据
      floorData:[]
    }

    config = {
    }

    methods = {
        toImageDetail(url){
            console.log(url);
            wepy.navigateTo({
                url:url
            })
        },
        toGoodList(url){
            wepy.navigateTo({
                url:url
            })
        }
    }
    //获取轮播图数据
    async getSwiers(){
        const res = await wepy.get("/home/swiperdata")
        if(res.data.meta.status !== 200) return wepy.baseToast()
        this.swipers = res.data.message;
        this.$apply();
    }
    //获取导航数据
    async getNavCate(){
        const res = await wepy.get("/home/catitems")
        if(res.data.meta.status !== 200) return wepy.baseToast();
        this.navCate = res.data.message;
        this.$apply();
    }
    //获取商品楼层数据
    async getFloor(){
        const res = await wepy.get("/home/floordata");
        if(res.data.meta.status !== 200) wepy.baseToast();
        this.floorData = res.data.message;
        this.$apply();
    }
    onLoad(){
        this.getSwiers();
        this.getNavCate();
        this.getFloor();
    }
    onShow(){
        this.$parent.setTabBarBadge();
      }
}
